let app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    type: "add",
    params: {
        title: ""
    },
    requestUrl: ""
  }, 
  titlechage:function(e){
    if(typeof(e.detail.value)!='undefined')
    {
      var params=this.data.params
      params['title']=e.detail.value
      this.setData({
        params:params
       })
    }
  },
  save:function(){
    var that=this
    if(this.data.type=='add'){
      wx.request({
        url: app.globalData.siteroot,
        data: {
          do:'Wordpool_addWord',
          staff_id:wx.getStorageSync('staff_bind_id'),
          title:that.data.params.title,
          class_id:that.data.class_id
        },
        success: function(res) {
          wx.showToast({
            title: '保存成功',
            icon: 'none',
            duration: 1500
          })
          setTimeout(function () {
            wx.navigateBack({
              delta:1, 
              success: function() {
              }
            })
          }, 500)
        }
      })
    }else{
      wx.request({
        url: app.globalData.siteroot,
        data: {
          do:'Wordpool_editWord',
          staff_id:wx.getStorageSync('staff_bind_id'),
          title:that.data.params.title,
          id:that.data.class_id
        },
        success: function(res) {
          wx.showToast({
            title: '保存成功',
            icon: 'none',
            duration: 1500
          })
          setTimeout(function () {
            wx.navigateBack({
              delta:1, 
              success: function() {
              }
            })
          }, 500)
        }
      })
    }
  
  },
  return:function(){
    wx.navigateBack({
      delta:1,
      success: function() {
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      this.setData({
        class_id:options.id,
        type:options.type,
        cont:options.cont
      })
      if(typeof(options.cont)!='undefined')
      {
        var params=this.data.params
        params['title']=options.cont
        this.setData({
          params:params
         })
      }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})